/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modificar;

import apunte.Carrera;
import dataBase.Db;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author martinLequerica
 */
public class modiCarrera extends JFrame{

    private JButton aceptar,cancelar;
    private String[] etiquetas ={"idcarrera","Nombre Carrera","Jefe de Departamento"};
    private JTextField[] texto ;
    modiCarrera(Carrera c) {
        super("Modificar Carrera");
        setLayout(new GridLayout(4, 2));
        texto = new JTextField[3];
        aceptar = new JButton("Aceptar");
        cancelar = new JButton("Cancelar");
        for (int i =0 ;i<etiquetas.length;i++){
            
            add(new JLabel(etiquetas[i]));
            texto[i] = new JTextField();
            add(texto[i]);
            
            
        }
        
    cargarCarrera(c);
    listeners();
        add(aceptar);
        add(cancelar);
        setVisible(true);
        setSize(300, 140);
    }

    private void cargarCarrera(Carrera c) {
        texto[0].setText(String.valueOf(c.getIdcarrera()));
        texto[0].setEditable(false);
        texto[1].setText(c.getNombreCarrera());
        texto[2].setText(c.getJefeDeDepartamento());
        
    }

    private void listeners() {
        aceptar.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
           
                Db db = new Db();
                Statement st = db.getStatement();
                String sql = "update carrera set nombreCarrera = '"+texto[1].getText()+"', jefeDeDepartamento = '"+texto[2].getText()+"' ";
                try {
                    st.execute(sql);
                    setVisible(false);
                } catch (SQLException ex) {
                    Logger.getLogger(modiCarrera.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                
            }
        });
        
        cancelar.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
           
                setVisible(false);
            }
        });
    }

    
    
}
